import { Byte } from '../../api/io/Byte';
import { HashMap } from '../../api/struct/HashMap';


export const enum E_CDSkill {
	/**ID*/
	id,
	/**技能名称key*/
	name,
	/**技能描述key*/
	note,
	/**技能描述参数格式*/
	noteParam,
	/**技能类型：1==普攻，2==被动，3==主动*/
	type,
	/**主动开场冷却时间,(单位毫秒)*/
	openCooldown,
	/**冷却时间,(单位毫秒)--普攻根据单位攻击间隔--被动技能会判断技能冷却*/
	cooldown,
	/**被动技能释放条件*/
	triggerType,
	/**被动技能释放参数*/
	triggerParam,
	/**能量消耗*/
	manaCost,
	/**能量消耗成长*/
	manaCostGrow,
	/**增加属性*/
	math,
	/**给敌人添加的效果s，多个效果通过|分隔*/
	enemyEffects,
	/**给自身添加的效果s，多个效果通过|分隔*/
	selfEffects,
	/**动画*/
	animation,
	/**图标，填写图标资源*/
	icon,
	/**敌人身上的战斗特效*/
	enemyBattleEffect,
	/**自己身上的战斗特效*/
	selfBattleEffect,
	/**特效大小比例，单位/百分比*/
	effectSize,
	/**特效偏移[x,y],单位像素/100*/
	effectOffset,
	/**特效延迟时间/ms*/
	effectDelay,

	/**枚举数量*/
	EnumCount
}



export class CDSkill{
	/**ID*/
	public id: number;
	/**技能名称key*/
	public name: number;
	/**技能描述key*/
	public note: number;
	/**技能描述参数格式*/
	public noteParam: string[];
	/**技能类型：1==普攻，2==被动，3==主动*/
	public type: number;
	/**主动开场冷却时间,(单位毫秒)*/
	public openCooldown: number;
	/**冷却时间,(单位毫秒)--普攻根据单位攻击间隔--被动技能会判断技能冷却*/
	public cooldown: number;
	/**被动技能释放条件*/
	public triggerType: number;
	/**被动技能释放参数*/
	public triggerParam: number;
	/**能量消耗*/
	public manaCost: number;
	/**能量消耗成长*/
	public manaCostGrow: number;
	/**增加属性*/
	public math: number;
	/**给敌人添加的效果s，多个效果通过|分隔*/
	public enemyEffects: number[];
	/**给自身添加的效果s，多个效果通过|分隔*/
	public selfEffects: number[];
	/**动画*/
	public animation: number;
	/**图标，填写图标资源*/
	public icon: string;
	/**敌人身上的战斗特效*/
	public enemyBattleEffect: string;
	/**自己身上的战斗特效*/
	public selfBattleEffect: string;
	/**特效大小比例，单位/百分比*/
	public effectSize: number;
	/**特效偏移[x,y],单位像素/100*/
	public effectOffset: number[];
	/**特效延迟时间/ms*/
	public effectDelay: number;


	/**获取属性值*/
	public getAttr(idx: number): any {
		switch(idx) { 
			default: return;
			case E_CDSkill.id: return this.id;
			case E_CDSkill.name: return this.name;
			case E_CDSkill.note: return this.note;
			case E_CDSkill.noteParam: return this.noteParam;
			case E_CDSkill.type: return this.type;
			case E_CDSkill.openCooldown: return this.openCooldown;
			case E_CDSkill.cooldown: return this.cooldown;
			case E_CDSkill.triggerType: return this.triggerType;
			case E_CDSkill.triggerParam: return this.triggerParam;
			case E_CDSkill.manaCost: return this.manaCost;
			case E_CDSkill.manaCostGrow: return this.manaCostGrow;
			case E_CDSkill.math: return this.math;
			case E_CDSkill.enemyEffects: return this.enemyEffects;
			case E_CDSkill.selfEffects: return this.selfEffects;
			case E_CDSkill.animation: return this.animation;
			case E_CDSkill.icon: return this.icon;
			case E_CDSkill.enemyBattleEffect: return this.enemyBattleEffect;
			case E_CDSkill.selfBattleEffect: return this.selfBattleEffect;
			case E_CDSkill.effectSize: return this.effectSize;
			case E_CDSkill.effectOffset: return this.effectOffset;
			case E_CDSkill.effectDelay: return this.effectDelay;
		}
	}



	/**设置属性值*/
	public setAttr(idx: number, v: any): void {
		switch(idx) { 
			default: break;
			case E_CDSkill.id: this.id = v; break;
			case E_CDSkill.name: this.name = v; break;
			case E_CDSkill.note: this.note = v; break;
			case E_CDSkill.noteParam: this.noteParam = v; break;
			case E_CDSkill.type: this.type = v; break;
			case E_CDSkill.openCooldown: this.openCooldown = v; break;
			case E_CDSkill.cooldown: this.cooldown = v; break;
			case E_CDSkill.triggerType: this.triggerType = v; break;
			case E_CDSkill.triggerParam: this.triggerParam = v; break;
			case E_CDSkill.manaCost: this.manaCost = v; break;
			case E_CDSkill.manaCostGrow: this.manaCostGrow = v; break;
			case E_CDSkill.math: this.math = v; break;
			case E_CDSkill.enemyEffects: this.enemyEffects = v; break;
			case E_CDSkill.selfEffects: this.selfEffects = v; break;
			case E_CDSkill.animation: this.animation = v; break;
			case E_CDSkill.icon: this.icon = v; break;
			case E_CDSkill.enemyBattleEffect: this.enemyBattleEffect = v; break;
			case E_CDSkill.selfBattleEffect: this.selfBattleEffect = v; break;
			case E_CDSkill.effectSize: this.effectSize = v; break;
			case E_CDSkill.effectOffset: this.effectOffset = v; break;
			case E_CDSkill.effectDelay: this.effectDelay = v; break;
		}
	}


	/**数据*/
	public static datas: HashMap<number, CDSkill> = new HashMap<number, CDSkill>();



	/**加载数据*/
	public static load(byte: Byte): void{
		const size = byte.readInt32();
		const list : CDSkill[] = [];
		let i :number;

		for (i = 0; i < size; i++) {
			list[i] = new CDSkill();
		}
		for (i = 0; i < size; i++) {
			list[i].id = byte.readInt32();
			this.datas.put(list[i].id, list[i]);
		}
		for (i = 0; i < size; i++) {
			list[i].name = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].note = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].noteParam = [];
			const attrArray = list[i].noteParam;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readString();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].type = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].openCooldown = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].cooldown = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].triggerType = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].triggerParam = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].manaCost = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].manaCostGrow = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].math = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].enemyEffects = [];
			const attrArray = list[i].enemyEffects;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].selfEffects = [];
			const attrArray = list[i].selfEffects;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].animation = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].icon = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].enemyBattleEffect = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].selfBattleEffect = byte.readString();
		}
		for (i = 0; i < size; i++) {
			list[i].effectSize = byte.readInt32();
		}
		for (i = 0; i < size; i++) {
			list[i].effectOffset = [];
			const attrArray = list[i].effectOffset;
			const arraySize = byte.readInt32();
			for (let j = 0; j < arraySize; j++) {
				attrArray[j] = byte.readInt32();
			}
		}
		for (i = 0; i < size; i++) {
			list[i].effectDelay = byte.readInt32();
		}
	}


	/** 获取数据*/
	public static getData(id: number): CDSkill{
		return this.datas ? this.datas.get(id) : null;
	}
}
